<?php
class kernel
{	
	var $sql;	
	var $result;
	var $rcount = 0;	
	function floorTime($day1,$day2)
    {
		

		if ($day1 < $day2) {
		$tmp = $day2;
		$day2 = $day1;
		$day1 = $tmp;
		}
		return ($day1 - $day2) / 86400;
    }
	function GetArrList($p,$tab = '',$type = '')
	{		
		$rn = '';
		$p = explode(',',$p);
		$tab = explode(',',$tab);
		foreach($p as $k => $v)
		{
			if($type == 'p')
			{
				$rn .= '<p>' .$this->GetField($v,$tab[$k],'title').'</p>';
			}
			else
				$rn .= '<p style="line-height:24px">' .$v.'</p>';
		}
		return $rn;
	}
	function GetInfoList($tab,$length = 0,$condition = 1,$order = 'udatetimes',$byway = 'desc')
	{
		global $dbo;
		$orderby = '';
		$order = explode(',',$order);
		$byway = explode(',',$byway);
		foreach($order as $k => $v)
		{
			$orderby .= $orderby == ''?($v. ' '.$byway[$k]):(',' . ($v. ' '.$byway[$k]));
		}
		$this->sql = 'select * from @db__'. $tab . ' where ' . $condition .' order by ' . $orderby;
		if($length >0)
			$this->sql = $this->sql . ' limit ' . $length;
		$this->result = $dbo->select($this->sql);
		return $this->result;
	}
	function GetSplitList($tab,$page = 1,$size = 4,$condition = 1,$order = 'updatetimes',$byway = 'desc')
	{
		global $dbo;
		$orderby = '';
		$page = $page + 0;
		if($page <= 0)
			$page = 1;
		$limit = ($page -1) * $size;
		$order = explode(',',$order);
		$byway = explode(',',$byway);
		foreach($order as $k => $v)
		{
			$orderby .= $orderby == ''?($v. ' '.$byway[$k]):(',' . ($v. ' '.$byway[$k]));
		}		
		$this->sql = 'select * from @db__'. $tab . ' where ' . $condition .' order by ' . $orderby . ' limit ' . $limit . ',' . $size;
		$this->result = $dbo->select($this->sql);	
		if($this->rcount == 0)
		{
			$this->sql = 'select count(id) as rcount from @db__'. $tab . ' where ' . $condition;
			$this->rcount = $dbo->single($this->sql);
			$this->rcount = $this->rcount['rcount'];
		}
		return $this->result;
	}
	function GetSingleInfo($tab,$condition=1)
	{
		global $dbo;
		$this->sql = 'select * from @db__'. $tab . ' where ' . $condition;		
		$this->result = $dbo->single($this->sql);
		return $this->result;
	}
	function GetField($id,$tab,$field)
	{
		global $dbo;
		if($id == 0)
		{
			$this->result = ' - ';
		}
		else
		{
			$this->sql = 'select ' .$field. ' from `@db__' .$tab.'` where id=' .$id;
			$this->result = $dbo->single($this->sql);
			$this->result = $this->result[$field];
		}
		return $this->result;
	}
	function GetUser($id,$tab,$field)
	{
		global $dbo;
		if($id == 0)
		{
			$this->result = ' - ';
		}
		else
		{
			$this->sql = 'select ' .$field. ' from `@db__' .$tab.'` where uid=' .$id;
			$this->result = $dbo->single($this->sql);
			$this->result = $this->result[$field];
		}
		return $this->result;
	}
	function GetStatus($type)
	{
		$rn = '';
		switch ($type)
		{
			case 'tm':$rn = '天猫';break;
			case 'tb':$rn = '淘宝';break;
			case 'jd':$rn = '京东';break;
			case 'dd':$rn = '当当';break;
			case '1':$rn = '<font style="color:#360">正常销售</font>';break;
			case '100':$rn = '<font style="color:#f00">热门推荐</font>';break;
			case '0':$rn = '<font style="color:#ccc">下架商品</font>';break;
			default :$rn = '<font style="color:#ccc">下架商品</font>';break;
		}
		return $rn;
	}
	function GetModule($type)
	{
		$rn = '';
		switch($type)
		{
			case 'news':$rn = '评测导购';break;
			case 'goods':$rn = '商品信息';break;
			case 'activity':$rn = '特品特惠';break;
			case 'single':$rn = '单页信息';break;
			case 'seo':$rn = 'SEO信息';break;
			case 'comment':$rn = '评论信息';break;
			case 'flink':$rn = '友情链接';break;
			case 'adv':$rn = '广告图片';break;
			case 'catalog':$rn = '频道节点';break;				
			case 'hotkey':$rn = '搜索关键字';break;		
		}
		return $rn;
	}
	function GetAdvType($type)
	{
		$rn = '';
		switch($type)
		{
			case 'banner':$rn = '网站首页轮显图片';break;
			case 'focus':$rn = '网站首页焦点图片';break;			
			case 'member':$rn = '登录注册轮显图片';break;			
		}
		return $rn;
	}
	function GetTotal($tab,$condition = 1)
	{
		global $dbo;
		$this->sql = 'select count(id) as num from `@db__' .$tab. '` where ' .$condition;
		$this->result = $dbo->single($this->sql);
		$this->result = $this->result['num'];
		return $this->result;
	}
}
global $tpl;
$tpl = new kernel;
?>